package utils;

import javafx.scene.control.Alert;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
import model.AttributeDefinition;
import model.LogisticsInfo;
import model.LogisticsRequirement;
import model.excel.LogisticsExcel;
import model.vo.QueryRequirementVO;
import service.AttributeService;

import java.io.File;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;

/**
 * @Description 下载模板
 * @Author zengzerui
 * @Date 2025/5/1
 */
public class ExcelLoadUtil {
    //下载客户信息excel模板
    public static void loadLogisticsExcel() {
        FileChooser fileChooser = new FileChooser();
        fileChooser.setTitle("保存Excel文件");
        fileChooser.getExtensionFilters().add(
                new FileChooser.ExtensionFilter("Excel文件", "*.xlsx")
        );

        String fileName = "客户物流信息_模板" + ".xlsx";
        fileChooser.setInitialFileName(fileName);

        File file = fileChooser.showSaveDialog(new Stage());
        if (file != null) {
            ExcelExportUtil.exportLogistics(new ArrayList<>(), file.getAbsolutePath());
            CommonUtil.showAlert("导出成功", "模板已成功导出！", Alert.AlertType.INFORMATION);
        }
    }

    //下载物流运输需求excel模板
    public static void loadRequirementExcel() {
        FileChooser fileChooser = new FileChooser();
        fileChooser.setTitle("保存Excel文件");
        fileChooser.getExtensionFilters().add(
                new FileChooser.ExtensionFilter("Excel文件", "*.xlsx")
        );
        String fileName = "配送需求_模板" + ".xlsx";
        fileChooser.setInitialFileName(fileName);

        File file = fileChooser.showSaveDialog(new Stage());
        List<QueryRequirementVO> requirements = new ArrayList<>();
        for (int i = 0;i < 10;i++){
            QueryRequirementVO requirement = new QueryRequirementVO();
            requirement.setSerial_no_str(Integer.toString(i));
            requirements.add(requirement);
        }
        ExcelExportUtil.exportLogisticsRequirement(requirements,file.getAbsolutePath());

        CommonUtil.showAlert("导出成功", "模板已成功导出！", Alert.AlertType.INFORMATION);
    }
}
